<template>
  <div class="shop-home-goods">
    <van-pull-refresh v-model="refreshing"
                      @refresh="onRefresh">
      <van-list v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="onLoad">
        <div class="shop-goos-list">
          <good-card-big-item v-for="item in 12"
                              :key="item"></good-card-big-item>
        </div>

      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import getList from '@/api/home'
import GoodCardBigItem from '@/components/GoodCardBigItem'
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
    };
  },
  components: {
    GoodCardBigItem
  },
  created () { },
  methods: {
    onLoad () {
      if (this.refreshing) {
        this.list = [];
        this.refreshing = false;
      }
      getList().then(res => {
        this.list = [...this.list, ...res.data.rows]

        this.loading = false;
        if (this.list.length >= res.data.total) {
          this.finished = true;
        }
      })
    },
    onRefresh () {
      // 清空列表数据
      this.finished = false;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
  }
}

</script>

<style lang='scss' scoped>
.shop-home-goods {
  width: 100%;
  .van-list {
    .shop-goos-list {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
      box-sizing: border-box;
      padding: 0 0.3rem;
    }
  }
}
</style>